/*
 * Copyright (c) 2010, University of Innsbruck, Austria.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package at.sti2.sepn.agent;

import java.util.HashMap;
import java.util.Map;

import at.sti2.sepn.agent.exception.AgentException;

import com.sun.tools.corba.se.idl.constExpr.Terminal;

public abstract class AbstractAgent {
	
	private Map<String, Terminal> inputTerminals = null;
	private Map<String, Terminal> outputTerminals = null;
	
	public AbstractAgent (){
		inputTerminals = new HashMap<String, Terminal> ();
		outputTerminals = new HashMap<String, Terminal> ();
	}
	
	/**
	 * Getter and setter methods
	 */
	
	public void addInputTerminal(String terminalId, Terminal inputTerminal) throws AgentException{
		
		if (inputTerminals.containsKey(terminalId))
			throw new AgentException("Input terimal with the idnetifier " + terminalId + " already exists.");
		
		inputTerminals.put(terminalId, inputTerminal);
	}
	
	public void addOutputTerminal(String terminalId, Terminal outputTerminal) throws AgentException{
		
		if (outputTerminals.containsKey(terminalId))
			throw new AgentException("Output terimal with the idnetifier " + terminalId + " already exists.");
		
		outputTerminals.put(terminalId, outputTerminal);
	}
	
	public Terminal getInputTerminalById(String terminalId){
		Terminal inputTerminal = null;
		
		if ((terminalId!=null)&&(!terminalId.equals("")))
			if (inputTerminals.containsKey(terminalId))
				inputTerminal = inputTerminals.get(terminalId);
		
		return inputTerminal;
	}
	
	public Terminal getOutputTerminalById(String terminalId){
		Terminal outputTerminal = null;
		
		if ((terminalId!=null)&&(!terminalId.equals("")))
			if (outputTerminals.containsKey(terminalId))
				outputTerminal = outputTerminals.get(terminalId);
		
		return outputTerminal;		
	}
}
